define(function(require, exports, module) {
    "use strict";
    var $ = require("$"),
        app = require("dist/application/app"),
        config = app.config,
        method = app.method;
        $(document).on("click", '[data-toggle="download"]', function() {
	      	var  $this=$(this),$form=$this.closest('form'),data=$this.data("set"),type=$this.data("type")||"get",
	      	action=$this.data("action"),time=$("#reportrange").val();
	      	if(time){
	      		time=time.split("-");
	      		var start=new Date(time[0].replace("-", "/").replace("-", "/"));  
	    		var end=new Date(time[1].replace("-", "/").replace("-", "/"));  
	    		var limit=(end-start)/(24*60*60*1000);
		      	if ($form.length&&limit<31) {
		            var  formdata=$form.serializeArray();
		             formdata.push({name:'set',value:data});
			         method.OpenWindowWithPost(action||$form.attr("action"),"_blank",formdata,type);
		      	}else{
		      		config.msg.error( "每次最多只能导出31天内的订单数据")
		      	}
		      }else{
		      	config.msg.error( "请选择日期每次最多只能导出31天内的订单数据")
		      }
	      	
	    })
	    $(document).on("click",".js_multy_dispatch",function(){
	    	var $this=$(this),path=$this.data("action"),type=$this.data("type")||"post",data=$this.data("set");
	    	var  formdata=[];

		    formdata.push({name:'ids',value:data.ids});
	    	method.OpenWindowWithPost(path,"_blank",formdata,type);
	    });
	    $(document).on("keyup",".js_price_input",function(){
	    	var $total=$(".js_total"),$show=$(".js_total_show"),total=0;
	    	if(!$(this).hasClass("error")){
	    		$(".js_price_input").each(function(){
		    		total=total+(($(this).val() || 0)-0);
		    	});
		    	$total.val(total.toFixed(2));
		    	$show.html(total.toFixed(2));
	    	}
	    	
	    });

	    $(document).on('shown.bs.tab', ".js_shipments_select_tab a[data-toggle='tab']",function (e) {
	    	var $this=$(e.target),type=$this.data("type"),$form=$this.closest('form');
	    	$(".js_shipments_select",$form).val(type);
		})
})